package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.Apply;
import cn.wolfcode.trip.base.domain.Companion;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.CompanionQueryObject;
import cn.wolfcode.trip.base.service.IApplyService;
import cn.wolfcode.trip.base.service.ICompanionService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**wq
 * 结伴资源控制器
 */
@RestController
@RequestMapping("companions")
public class CompanionController {

    @Autowired
    private ICompanionService companionService;

    @Autowired
    private IApplyService applyService;

    /**wq
     * 获取所有结伴
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo<Companion> list(CompanionQueryObject qo){
        qo.setPageSize(4);
        qo.setOrderBy("c.createTime desc");
        PageInfo<Companion> query = companionService.query(qo);
        return query;
    }


    /**wq
     * 根据结伴id查询具体结伴内容
     * @return
     */
    @GetMapping("{companionId}")
    public Companion getById(@PathVariable Long companionId){
        Companion companion = companionService.selectById(companionId);
        return companion;
    }

    /**wq
     * 用户发起结伴 保存
     * @param companion
     * @return
     */
    @PostMapping
    public JSONResult save(Companion companion){
        System.out.println(123);
        companionService.saveOrUpdate(companion);
        return new JSONResult();
    }

    /**wq
     * 对某篇结伴发起报名
     * @return
     */
    @PostMapping("{id}")
    public JSONResult apply(Apply apply){
        applyService.insert(apply);
        return new JSONResult();
    }

}
